package com.yoyo.yyadsdk.util;

import android.content.Context;

import com.anye.greendao.gen.AppEntityDao;
import com.anye.greendao.gen.DaoMaster;
import com.anye.greendao.gen.DaoSession;

public class GreenDaoManager {
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    private Context mContext;
    private static GreenDaoManager instance;

    /**
     * 对外唯一实例的接口
     */
    public static GreenDaoManager getInstance() {
        if (instance == null) {
            synchronized (GreenDaoManager.class) {
                if (instance == null) {
                    instance = new GreenDaoManager();
                }
            }
        }
        return instance;
    }

    /**
     * 初始化数据
     */
    public void init(Context context) {//MigrationHelper.DEBUG = true; //如果你想查看日志信息，请将DEBUG设置为true
//        MySQLiteOpenHelper helper = new MySQLiteOpenHelper(context, "yoyoos");
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "yoyoos");
        mDaoMaster = new DaoMaster(helper.getWritableDatabase());
        mDaoSession = mDaoMaster.newSession();
    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public DaoSession getNewSession() {
        mDaoSession = mDaoMaster.newSession();
        return mDaoSession;
    }
}